package com.itshen.jdk8;

import java.util.Arrays;
import java.util.Comparator;
import java.util.function.Predicate;

/**
 * 函数接口
 * @author: stephen.shen
 * @create: 2018-12-06 11:19
 */
public class FunctionalInterfaceDemo {

    public static void main(String[] args) {

    }

    /**
     * 条件检测接口
     */
    public static void testPredicate(){
        Predicate<Integer> predicate = x -> x > 3;

        //true
        predicate.test(10);
        //false
        predicate.negate().test(10);
        //true
        predicate.or(x -> x < 1).and(x -> x > -1).negate().test(-1);
    }

    /**
     * 比较接口
     */
    public static void testComparator(){
        Integer[] a = new Integer[]{3, 1, 2, 4, 6, 5};
        Comparator<Integer> comparator = Integer::compare;

        Arrays.sort(a, comparator);
        System.out.println("升序：" + Arrays.toString(a));

        Arrays.sort(a,comparator.reversed());
        System.out.println("降序："+Arrays.toString(a));
    }

    public static void testSupplier(){

    }

    public static void testConsumer(){

    }
}
